import React, { PureComponent,Fragment } from "react";
import { connect } from "dva";
import moment from "moment";
import { Row, Col, Table, Spin, Card } from "antd";





@connect(({ warn, loading }) => ({
  tableData: warn.dependentHistoryWarn,
  loading: loading.models.warn,
}))
export default class Repairlog extends PureComponent {
  constructor(props) {
    super(props);
    this.state={
      currentPage: 1,
      pageSize: 10,
    }
  }

  componentDidMount() {
    const {currentPage,pageSize} = this.state;
    this.getDataList(pageSize,currentPage)
  }

  // componentWillReceiveProps(nextProps) {
  //   if (nextProps.detailInfoId && nextProps.detailInfoId !== this.props.detailInfoId) {
  //
  //   }
  // }


  getDataList(pageSize,currentPage) {
    const { dispatch,detailInfoId } = this.props;
    dispatch({
      type: 'warn/fetch_dependenthistory_warnlist',
      payload: {
        devId: detailInfoId,
        pageSize,
        currentPage
      },
    });
  }

  // 分页、排序、筛选变化时触发
  handleTableChange = (pagination, filtersArg, sorter) => {
    const { pageSize } = this.state;

    this.setState({
      currentPage:pagination.current
    },()=>{
      this.getDataList(pageSize,pagination.current);
    })

  };


  render() {
    const { tableData,loading } = this.props;

    const columns = [{
      title: '发生时间',
      dataIndex: 'createTime',
      render: text => moment(text).format("YYYY-MM-DD HH:mm")
    }, {
      title: '告警信息',
      dataIndex: 'warnCon',
    }, {
      title: '维保单位',
      dataIndex: 'maintenanceName',
    }, {
      title: '设备管理员',
      dataIndex: 'adminUserName',
    },{
      title: '持续时间',
      dataIndex: 'continueTime',
    },{
      title: '处理人',
      dataIndex: 'handler',
    },{
      title: '关闭时间',
      dataIndex: 'closeTime',
      render: text => text ? moment(text).format("YYYY-MM-DD HH:mm") : '--'
    }];


    return (
        <div style={{ padding: '0 12px' }}>
          <Table
            columns={columns}
            dataSource={tableData.list ? tableData.list : []}
            pagination={tableData.pagination}
            onChange={this.handleTableChange}
            loading={loading}
            rowKey={"warnId"}
          />
        </div>

    );
  }
}
